//
//  AnswerDetailVC.m
//  MZJ
//
//  Created by XDD on 16/6/30.
//  Copyright © 2016年 XDD. All rights reserved.
//

#import "AnswerDetailVC.h"

@interface AnswerDetailVC ()<UIWebViewDelegate,UIScrollViewDelegate,ModelDelegate>

@property (nonatomic, strong) UIWebView *answer_Detail_webView;
@property (nonatomic, strong) ModelViewController *modelViewController;
@property (nonatomic, strong) JSNetWorkingModel *model;

@end

@implementation AnswerDetailVC
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = YES;
    self.tabBarController.tabBar.hidden = YES;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.topBar.backgroundColor = [UIColor colorWithRed:253/255.0 green:179/255.0 blue:10/255.0 alpha:1];
    self.titleLabel.text = @"详情";
    self.view.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
    [self.backButton setTitle:@"" forState:UIControlStateNormal];
    
    _answer_Detail_webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 55, kWidth, kHeight - 55)];
    _answer_Detail_webView.delegate = self;
    _answer_Detail_webView.scrollView.delegate = self;
    [self.view addSubview:_answer_Detail_webView];
    
    if (!_modelViewController) {
        _modelViewController = [[ModelViewController alloc]init];
        [_modelViewController modelUrl_Http_Request:accord_info_model fileName:@"VolunteerModel.txt" webview:_answer_Detail_webView];
    }
    
    if (!_model) {
        _model = [[JSNetWorkingModel alloc]init];
    }

}

//点击返回键
- (void)clickedBackButton:(UIButton *)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
    self.tabBarController.tabBar.hidden = YES;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView  {
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:[DataModel object].Volunteer_ID_Str forKey:@"mmmbid"];
    __weak typeof (self)weakSelf = self;
    [_model setBlockWithReturnBlock:^(id returnValue) {
        
        NSLog(@"%@",returnValue);
        //        NSString* aStr= [[NSString alloc] initWithData:returnValue encoding:NSUTF8StringEncoding];
        //        NSString *sddsd = [NSString stringWithFormat:@"Home.help_home.V.create(%@)",aStr];
        //
        //        [weakSelf.rescue_webView stringByEvaluatingJavaScriptFromString:sddsd];
        [weakSelf.modelViewController JS_datarequestinitWebView:@"Home.accord_info.V.create" andData:returnValue andwebView:weakSelf.answer_Detail_webView];
        
    } WithErrorBlock:^(id errorCode) {
        
    }];
    
    [_model JS_HomeGetaccord_info:dic];
    [GiFHUD dismiss];

}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
    [GiFHUD show];

}

- (BOOL)webView: (UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSString *requestString = [[[request URL] absoluteString] stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    
    NSLog(@"%@",requestString);
    
    if ([requestString rangeOfString:accord_Detail_info].location != NSNotFound) {
        
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setObject:[DataModel object].Volunteer_ID_Str forKey:@"mmmbid"];
        __weak typeof (self)weakSelf = self;
        [_model setBlockWithReturnBlock:^(id returnValue) {
            
            NSLog(@"%@",returnValue);
            //        NSString* aStr= [[NSString alloc] initWithData:returnValue encoding:NSUTF8StringEncoding];
            //        NSString *sddsd = [NSString stringWithFormat:@"Home.help_home.V.create(%@)",aStr];
            //
            //        [weakSelf.rescue_webView stringByEvaluatingJavaScriptFromString:sddsd];
            [weakSelf.modelViewController JS_datarequestinitWebView:@"Home.accord_info.V.create" andData:returnValue andwebView:weakSelf.answer_Detail_webView];
            
        } WithErrorBlock:^(id errorCode) {
            
        }];
        
        [_model JS_HomeGetaccord_info:dic];
        
        return NO;
    }
    
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
